package com.corechina.apex_osswords.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.corechina.apex_osswords.common.Response;
import com.corechina.apex_osswords.common.WeiXinUserUtils;
import com.corechina.apex_osswords.domain.dao.CoreProjectUserMapper;
import com.corechina.apex_osswords.domain.entity.CoreProjectUser;
import com.corechina.apex_osswords.domain.vo.CoreMaintenanceEngineerVo;
import com.corechina.apex_osswords.service.ICoreProjectUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 项目--人员配置表 服务实现类
 * </p>
 *
 * @author cc
 * @since 2022-03-11
 */
@Service
public class CoreProjectUserServiceImpl extends ServiceImpl<CoreProjectUserMapper, CoreProjectUser> implements ICoreProjectUserService {

    @Autowired
    private CoreProjectUserMapper coreProjectUserMapper;

    @Override
    public Response getProjectPersonnelList(Integer queryType, Integer projectId, String name, String company, Integer engineerType, Integer pageIndex, Integer pageSize) {
        IPage<CoreMaintenanceEngineerVo> projectVoIPage = coreProjectUserMapper.getProjectPersonnelList(new Page(pageIndex, pageSize), queryType, projectId, name, company, engineerType);
        return Response.ok(projectVoIPage.getRecords(), projectVoIPage.getTotal());
    }

    @Override
    public Response delByUserId(Integer userId) {
        QueryWrapper<CoreProjectUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        coreProjectUserMapper.delete(queryWrapper);
        return Response.ok();
    }

    @Override
    public int getCountByUserAndProject(Integer projectId) {
        return coreProjectUserMapper.getCountByUserAndProject(WeiXinUserUtils.getUserId(), projectId);
    }

}
